﻿<Window x:Class="ContinuousLinq.OrderBookDemo.Views.MainWindow"
		xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:models="clr-namespace:ContinuousLinq.OrderBookDemo.Models"
        xmlns:converters="clr-namespace:ContinuousLinq.OrderBookDemo.Converters"
		Title="CLINQ v2 - Order Book Demo"
		Background="{StaticResource Brushes/BlackGradient}">
    <Window.Resources>
        <models:OrderCollection x:Key="DataSource" />
        <models:ModelRoot x:Key="ModelRoot" />
        <converters:PriceConverter x:Key="PriceConverter"/>
        <converters:TickCollectionToPointCollectionConverter x:Key="TickCollectionFormatter" />

        <DataTemplate x:Key="ColumnHeaderTemplate">
            <TextBlock Text="{Binding}"
					   Foreground="White"
					   FontWeight="Bold" />
        </DataTemplate>

        <DataTemplate x:Key="PriceTemplate">
            <TextBlock Text="{Binding Price, Converter={StaticResource PriceConverter}}"
					   Foreground="Black"
					   FontWeight="Bold" />
        </DataTemplate>

        <DataTemplate x:Key="QuantityTemplate">
            <TextBlock Text="{Binding Quantity}"
					   Foreground="Black"
					   FontWeight="Bold" />
        </DataTemplate>

        <LinearGradientBrush x:Key="textGradient" StartPoint="0,0" EndPoint="0,1">
            <GradientStop Color="White" Offset="0.0"/>
            <GradientStop Color="DarkCyan" Offset="1.0"/>
        </LinearGradientBrush>

        <Style x:Key="ColumnHeaderStyle"
			   TargetType="GridViewColumnHeader">
            <Setter Property="Height"
					Value="25" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="GridViewColumnHeader">
                        <Border Background="{StaticResource Brushes/HeaderBrush}"
								BorderBrush="Black"
								BorderThickness="1,1,0,1">
                            <ContentPresenter HorizontalAlignment="Left"
											  VerticalAlignment="Center"
											  Margin="5,0,0,0"
											  Content="{TemplateBinding Content}"
											  ContentTemplate="{TemplateBinding ContentTemplate}" />
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="GridRowStyle"
			   TargetType="ListViewItem">
            <Setter Property="Height"
					Value="25" />
            <Setter Property="OverridesDefaultStyle"
					Value="True" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListViewItem">
                        <Border x:Name="Border"
								Background="Transparent">
                            <GridViewRowPresenter VerticalAlignment="Center" />
                        </Border>

                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver"
									 Value="True">
                                <Setter Property="Background"
										Value="{StaticResource Brushes/RowHilightBrush}"
										TargetName="Border" />
                            </Trigger>
                            <Trigger Property="IsSelected"
									 Value="True">
                                <Setter Property="Background"
										Value="{StaticResource Brushes/RowSelectionBrush}"
										TargetName="Border" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <GridView x:Key="GridViewTemplate"
				  AllowsColumnReorder="False"
				  ColumnHeaderContainerStyle="{StaticResource ColumnHeaderStyle}"
				  ColumnHeaderTemplate="{StaticResource ColumnHeaderTemplate}"
				  x:Shared="False">
            <GridView.Columns>
                <GridViewColumn Header="Price"
								Width="125"
								CellTemplate="{StaticResource PriceTemplate}" />
                <GridViewColumn Header="Quantity"
								Width="125"
								CellTemplate="{StaticResource QuantityTemplate}" />
            </GridView.Columns>
        </GridView>

        <Style TargetType="ListView">
            <Setter Property="ItemContainerStyle"
					Value="{StaticResource GridRowStyle}" />
            <Setter Property="Background"
					Value="{StaticResource Brushes/ListViewBackgroundBrush}" />
            <Setter Property="ScrollViewer.HorizontalScrollBarVisibility"
					Value="Hidden" />
            <Setter Property="ScrollViewer.CanContentScroll"
					Value="False" />
            <Setter Property="View"
					Value="{StaticResource GridViewTemplate}" />
        </Style>
    </Window.Resources>
    <Grid Background="{StaticResource Brushes/SwirlBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="160" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition Width="400"/>
        </Grid.ColumnDefinitions>

        <Image Source="/Resources/logo.png"
			   VerticalAlignment="Top"
			   HorizontalAlignment="Left"
			   Height="40"
			   Margin="10"
			   Grid.Row="0"
			   Grid.Column="0" />

        <TextBlock Grid.Row="0" Grid.Column="0" 
                   Foreground="{StaticResource textGradient}"
                   FontWeight="Bold"
                   FontFamily="Verdana"
                   FontSize="72"
                   Margin="50,50,20,20"
                   Text="AAPL"/>

        <DockPanel Grid.Column="1"
				   Grid.Row="0">
            <DockPanel.Resources>
                <Style TargetType="TextBlock">
                    <Setter Property="Foreground"
							Value="Green" />
                </Style>
            </DockPanel.Resources>
            <Grid DockPanel.Dock="Left">
                <TextBlock VerticalAlignment="Bottom" Text="{Binding Source={StaticResource ModelRoot}, Path=CurrentMin, Converter={StaticResource PriceConverter}}"/>
                <TextBlock VerticalAlignment="Bottom" Text="VWAP" Margin="-40,0,0,40"/> 
                <TextBlock VerticalAlignment="Bottom" Margin="0,0,0,40" Text="{Binding Source={StaticResource ModelRoot}, Path=CurrentVwap, Converter={StaticResource PriceConverter}}"/>
                
                <TextBlock VerticalAlignment="Top" Text="{Binding Source={StaticResource ModelRoot}, Path=CurrentMax, Converter={StaticResource PriceConverter}}"/>
            </Grid>
            <Canvas Background="{StaticResource Brushes/GraphBrush}"
					Margin="5,0,10,0">
                <Polyline x:Name="priceLine" Stroke="Yellow" StrokeThickness="1" 
                          Points="{Binding Path=GraphExecutions, Source={StaticResource ModelRoot}, Converter={StaticResource TickCollectionFormatter}}" 
                          Canvas.Top="0" Canvas.Left="0"/>
                <!-- <Path Stretch="Fill"
					  Stroke="Green"
					  StrokeThickness="2"
					  Canvas.Top="0"
					  Data="{Binding Path=Executions, Source={StaticResource ModelRoot}, Converter={StaticResource TickCollectionFormatter}}"/> -->

            </Canvas>
        </DockPanel>

        <Border Grid.Row="1"
				Grid.Column="0"
				Grid.ColumnSpan="2"
				BorderBrush="#555555"
				BorderThickness="2"
				Background="#7F000000"
				Margin="30,30,30,0"
				CornerRadius="15"
				Padding="10">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="30"/>
                    <RowDefinition />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition Width="40"/>
                    <ColumnDefinition />
                    <ColumnDefinition Width="40"/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>

                <TextBlock Foreground="Yellow" 
                               FontFamily="Segoe UI"
                               FontWeight="Bold"
                               FontSize="14"
                               Padding="5,5,5,5"
                               HorizontalAlignment="Center" 
                           Text="Bid"
                           Grid.Column="0"/>
                <TextBlock Foreground="Yellow" 
                               FontFamily="Segoe UI"
                               FontWeight="Bold"
                               FontSize="14"
                               Padding="5,5,5,5"
                               HorizontalAlignment="Center" Text="Ask"
                           Grid.Column="2"/>
                <TextBlock Foreground="Yellow" 
                               FontFamily="Segoe UI"
                               FontWeight="Bold"
                               FontSize="14"
                               Padding="5,5,5,5"
                               HorizontalAlignment="Center" Text="Executions"
                           Grid.Column="4"/>

                <ListView ItemsSource="{Binding Source={StaticResource ModelRoot}, Path=Bids}"
                          Grid.Row="1"
                          Grid.Column="0"/>

                <ListView ItemsSource="{Binding Source={StaticResource ModelRoot}, Path=Asks}"
                          Grid.Column="2"
                          Grid.Row="1"/>
                <ListView ItemsSource="{Binding Source={StaticResource ModelRoot}, Path=Executions}"
                          Grid.Column="4"
                          Grid.Row="1"/>

            </Grid>
        </Border>
    </Grid>
</Window>
